package com.example.myframe;

import com.alibaba.android.arouter.launcher.ARouter;
import com.hjq.http.EasyConfig;
import com.hjq.http.config.IRequestHandler;
import com.a.lib_base.BaseApp;
import com.tencent.mmkv.MMKV;
import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;

/**
 * 初始化了ARouter、MMKV
 */
public abstract class BaseNetApp extends BaseApp {

    /**
     * 初始化网络请求设置
     */
    public static void setNetConfig(String host, long timeout, IRequestHandler requestHandler) {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .writeTimeout(30L, TimeUnit.SECONDS)
                .readTimeout(30L, TimeUnit.SECONDS)
                .connectTimeout(timeout, TimeUnit.SECONDS)
//                .callTimeout(timeout, TimeUnit.SECONDS)
                .build();
        EasyConfig.with(okHttpClient)
                .setLogEnabled(BuildConfig.DEBUG)// 是否打印日志
                .setServer(host)// 设置服务器配置
                .setHandler(requestHandler)
                .into();
//            .setHandler(RequestHandler()) // 设置请求处理策略
//            .setRetryCount(3)// 设置请求重试次数
        //.addParam("token", "6666666")// 添加全局请求参数
        // 添加全局请求头
        //.addHeader("time", "20191030")
        // 启用配置

    }

    @Override
    public void onCreate() {
        super.onCreate();
        ARouter.init(this);
        if (BuildConfig.DEBUG) {
            ARouter.openLog();
            ARouter.openDebug();
            // 打印日志的时候打印线程堆栈
            ARouter.printStackTrace();
        }
        MMKV.initialize(this);//MMKV初始化

    }
}